#include <iostream>
#include <string>
#include <functional>
#include <vector>

//bind的两种用法
//1.提前绑死参数，影响实际调用时的传参，不影响作为参数传递时，bind和function的类型
//2.提前预留参数，等到实际调用的时候，由调用者进行传参。
void print(const std::string &str, int num)
{
    std::cout << str << num << std::endl;
}
int main()
{
    using Task = std::function<void()>;
    std::vector<Task> tqueue;
    //bind绑死参数后生成的对象可以直接传递给Task类型，tqueue调用时直接调用即可，无须传递任何参数
    tqueue.push_back(std::bind(print, "hello", 10));
    tqueue.push_back(std::bind(print, "good morning", 9));
    tqueue.push_back(std::bind(print, "good bye", 8));
    tqueue.push_back(std::bind(print, "see you tomorrow", 7));
    for (auto t : tqueue) t();

    auto func = std::bind(print, "hello", std::placeholders::_1);
    func(99); //实际调用func的时候，传递第二个参数num
    return 0;
}